# -*- coding: utf_8 -*-
# @Author : RSW
# @Time : 2022/1/8
# @Remark: pyweb
import time

from pydantic import constr
from mxsoftpy import Model


class DeleteModel(Model):
    """基础模型"""
    is_del: int = 0


def group_fields(field):
    """机房组别名模型"""
    fields_dict = {
        'name': 'group_name',
        'parent': "group_parent"
    }
    return fields_dict.get(field) or field


class GroupModel(DeleteModel):
    """机房组创建模型"""
    name: constr(min_length=1, max_length=50)  # 机房组名称
    parent: str = ""  # 机房组上层，没有上层为空
    type: int = 1  # 机房组描述

    class Config:
        alias_generator = group_fields


class GroupUpdateModel(Model):
    """机房组更新模型"""
    name: constr(min_length=1, max_length=50) = None  # 机房组名称
    parent: str = None  # 机房组上层，没有上层为空

    class Config:
        alias_generator = group_fields


def sroom_fields(field):
    """机房别名模型"""
    fields_dict = {
        'name': 'sroom_name',
        'parent': "group_parent",
        'desc': 'sroom_desc'
    }
    return fields_dict.get(field) or field


class SRoomModel(DeleteModel):
    """机房新建模型"""
    name: constr(min_length=1, max_length=50)  # 机房名称
    parent: str = ""  # 机房上层，没有上层为空
    type: int = 2  # 机房描述
    desc: constr(max_length=300) = ""  # 机房备注
    update_time: int = int(time.time())

    class Config:
        alias_generator = sroom_fields


class SRoomUpdateModel(Model):
    """机房修改模型"""
    name: constr(min_length=1, max_length=50) = None  # 机房名称
    parent: str = None  # 机房上层，没有上层为空
    desc: constr(max_length=300) = None  # 机房备注

    class Config:
        alias_generator = sroom_fields


# class TagModel(Model):
#     key: constr(min_length=1, max_length=50)          # 标签的key
#     value: constr(min_length=1, max_length=50)        # 标签的value
#     parent: constr(max_length=100) = ""               # 标签的所属的标签组
#     parent_name: constr(max_length=100) = "未分组"     # 所属标签组的名称，提高查询效率
#     update_time_stamp: int                            # 标签最后修改的时间

